using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Prologis.ShifterNT.Datasource
{


    public class TextfileReader : IEnumerable<string>, IDisposable
    {

        StreamReader sr;


        /// <summary>
        /// 
        /// </summary>
        /// <param name="path"></param>
        /// 
        public TextfileReader(string path, Encoding encoding)
        {
            sr = new StreamReader(path, encoding);
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="path"></param>
        /// 
        public TextfileReader(string path)
        {
            sr = new StreamReader(path);
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        public void Dispose()
        {
            if (sr != null) sr.Close();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        /// 
        public IEnumerator<string> GetEnumerator()
        {
            while (sr.Peek() != -1)
            {
                yield return sr.ReadLine();
            }
            Dispose();
        }


        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        /// 
        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }
}
